// pages/myOrder/myOrder.js
const utils = require('../../utils/util');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail: 0, // 0-待付款, 1-已付款
    orders:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    this.setData({
      detail: options.type || 0,
    })
    const { data } = await utils.request('GET','/order/getOrdersByState',{state:0});
    this.setData({
        orders: data
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  changTab: async function (e) {
    const detail = Number(e.currentTarget.dataset.value)
    const { data } = await utils.request('GET','/order/getOrdersByState',{state:detail});
    this.setData({
        detail: detail,
        orders: data
    })
  },
  toMyOrderDetail: function(e) {
    const id = Number(e.currentTarget.dataset.value)
    wx.navigateTo({
      url: '/pages/myOrderDetail/myOrderDetail?id='+id,
    })
  }
})